package thomas.movie;

import   javax.swing.*;
import   java.awt.*;
import   java.awt.event.*;
public   class   DragWindow   extends   JWindow{
    private int   positionX;
    private int   positionY;
    private int width = 3000;
    private int height = 30;
    private int increment = 15;

    public   DragWindow()   {
        try   {
            jbInit();
        }
        catch(Exception   e)   {
            e.printStackTrace();
        }
    }
    private   void   jbInit()   throws   Exception   {
        this.addMouseListener(new   java.awt.event.MouseAdapter()   {
            public   void   mousePressed(MouseEvent   e)   {
                this_mousePressed(e);
            }

/*            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {
                //no useful, no effect
                this_mouseWheelMoved(e);
            }*/

            @Override
            public void mouseClicked(MouseEvent e) {
                this_mouseClicked(e);
            }
        });
        this.addMouseMotionListener(new   java.awt.event.MouseMotionAdapter()   {
            public   void   mouseDragged(MouseEvent   e)   {
                this_mouseDragged(e);
            }
        });
    }

    public void   this_mouseDragged(MouseEvent   e)   {
        Point   point   =   this.getLocation();
        this.setLocation(point.x   +   e.getX()   -   positionX,point.y   +   e.getY()   -   positionY);
    }

    public void   this_mousePressed(MouseEvent   e)   {
        positionX   =   e.getX();
        positionY   =   e.getY();
    }

    public void this_mouseClicked(MouseEvent e){
        if(SwingUtilities.isLeftMouseButton(e)){
            //System.out.println("left");
            if (e.getClickCount() == 2) {
                height += increment;
            }
        }else if(SwingUtilities.isRightMouseButton(e)){
            //System.out.println("right");
            if (e.getClickCount() == 2) {
                height -= increment;
            }
        }else if(SwingUtilities.isMiddleMouseButton(e)){
            height = 0;
            //System.out.println("middle");
        }else{
            System.out.println("Other mouse button is clicked!");
        }
        this.setSize(width,height);
        this.validate();
    }

    //利用滚轮事件将窗口放大和缩小
/*    public void this_mouseWheelMoved(MouseWheelEvent e) {
        System.out.println("==============");
        // TODO Auto-generated method stub
        if(e.getWheelRotation()==1){
            //width+=10;
            height+=10;
            this.setSize(width,height);
            this.validate();
            System.out.println("滑轮向前。。。。");
        }
        if(e.getWheelRotation()==-1){
            //width-=10;
            height-=10;
            this.setSize(width,height);
            this.validate();
            System.out.println("滑轮向后....");
        }
    }*/

    public void paint(Graphics g) {
        g.setColor(new Color(0, 0, 0));
        //g.fillRect(0, 0, getSize().width, getSize().height);
        g.fillRect(0, 0, this.getSize().width, this.getSize().height);
    }

    /**
     *
     */
    public   static   void   main(String[]   args)   {
        DragWindow   dragWindow   =   new   DragWindow();
        dragWindow.setPreferredSize(new Dimension(dragWindow.getWidth(), dragWindow.getHeight()));
        dragWindow.pack();
        dragWindow.setVisible(true);
        dragWindow.setAlwaysOnTop(true);
    }


    @Override
    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    @Override
    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }
}
